# MicroPython 传感器读取示例
import time
import machine

# 创建一个 ADC 对象来读取模拟信号
adc = machine.ADC(0)  # 根据您的设备调整引脚

print("MicroPython 传感器读取示例")
print("每秒读取一次 ADC 值")
print("按 Ctrl+C 停止")

try:
    while True:
        # 读取 ADC 值 (0-1024)
        sensor_value = adc.read()

        # 转换为电压 (假设 3.3V 参考电压)
        voltage = sensor_value * 3.3 / 1024

        print(f"ADC 值: {sensor_value}, 电压: {voltage:.2f}V")
        time.sleep(1)

except KeyboardInterrupt:
    print("传感器读取已停止")
